import request from '@/utils/request'

/**
 * 课程管理相关接口
 */

export default {
  /**
   * 获取课程列表
   * @param {Object} params 查询参数 {name, category_id, status, page, page_size}
   * @returns Promise
   */
  getCourseList(params) {
    return request({
      url: '/teacher/courses',
      method: 'get',
      params
    })
  },

  /**
   * 获取课程分类列表
   * @param {Object} params 查询参数 {name}
   * @returns Promise
   */
  getCourseCategories(params) {
    return request({
      url: '/teacher/course-categories',
      method: 'get',
      params
    })
  },

  /**
   * 获取课程详情
   * @param {Number} id 课程ID
   * @returns Promise
   */
  getCourseDetail(id) {
    return request({
      url: '/teacher/course-detail',
      method: 'get',
      params: { id }
    })
  },

  /**
   * 新增课程
   * @param {Object} data 课程数据 {name, code, category_id, status, knowledge_ids, paper_ids}
   * @returns Promise
   */
  createCourse(data) {
    return request({
      url: '/teacher/courses',
      method: 'post',
      data
    })
  },

  /**
   * 编辑课程
   * @param {Object} data 课程数据 {id, name, code, category_id, status, knowledge_ids, paper_ids}
   * @returns Promise
   */
  updateCourse(data) {
    return request({
      url: '/teacher/courses',
      method: 'put',
      data
    })
  },

  /**
   * 删除课程
   * @param {Number} id 课程ID
   * @returns Promise
   */
  deleteCourse(id) {
    return request({
      url: `/teacher/courses/${id}`,
      method: 'delete'
    })
  },

  /**
   * 获取可选知识列表
   * @returns Promise
   */
  getAvailableKnowledges() {
    return request({
      url: '/teacher/available-knowledges',
      method: 'get'
    })
  },

  /**
   * 获取可选试卷列表
   * @returns Promise
   */
  getAvailablePapers() {
    return request({
      url: '/teacher/available-papers',
      method: 'get'
    })
  }
}